/*
 * Copyright (c) 2017 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.common.utils;

import com.google.common.base.Optional;

import java.math.BigDecimal;

/**
 * @author zhangcm
 * @version 1.0, 2017/10/6
 */
public class BigDecimalUtils {

    private BigDecimalUtils(){}

    public static BigDecimal add(BigDecimal v1, BigDecimal v2){
        v1 = Optional.fromNullable(v1).or(BigDecimal.ZERO);
        v2 = Optional.fromNullable(v2).or(BigDecimal.ZERO);
        return v1.add(v2);
    }

    public static BigDecimal sub(BigDecimal v1, BigDecimal v2){
        v1 = Optional.fromNullable(v1).or(BigDecimal.ZERO);
        v2 = Optional.fromNullable(v2).or(BigDecimal.ZERO);
        return v1.subtract(v2);
    }

    public static BigDecimal mul(BigDecimal v1, Integer v2){
        v1 = Optional.fromNullable(v1).or(BigDecimal.ZERO);
        v2 = Optional.fromNullable(v2).or(0);
        return v1.multiply(new BigDecimal(v2));
    }
}
